package com.client.view;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JPanel;

import java.awt.Color;
import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Image;
import java.awt.Label;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.border.LineBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;

import com.client.ctrl.RoatCtrl;
import com.entity.Announcement;
import com.entity.Student;
import com.entity.Teacher;
import com.entity.User;
import com.util.CommonUtil;
import com.util.DateChooser;
import com.util.FileTest;
import com.util.MyBorder;
import com.util.MyTable2;

public class RoatInfoManagePanel extends JPanel implements ChangeListener {
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	static JTabbedPane tabbPane;
	private static JPanel announcementPanel=null;
	private static JPanel userPanel=null;
	private static User user;
	private static RoatCtrl roatCtrl=new RoatCtrl();
	
	public RoatInfoManagePanel(User user){
		this.user=user;
		setBackground(new Color(252,251,248));
        setLayout(new BorderLayout(0, 0));
        
        tabbPane = new JTabbedPane(JTabbedPane.LEFT);
        tabbPane.setBackground(new Color(255,255,255));
        tabbPane.setForeground(Color.blue);
        tabbPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        tabbPane.setFont(new Font(null,Font.BOLD,24));
        tabbPane.addChangeListener(this);
        add(tabbPane);
        
		tabbPane.addTab("公告管理", null,null, null);
        
        tabbPane.addTab("用户管理", null, null, null);
        
        tabbPane.addTab("基本信息", null, null, null);
	}	
	

	public void stateChanged(ChangeEvent e) {
		if(tabbPane.getSelectedIndex()==0){
			
			announcementPanel = new JPanel();
			announcementPanel.setBackground(new Color(200,221,242));
			announcementPanel.setLayout(null);
	        
	        JLabel titleLabel = new JLabel("公告表");
			CommonUtil.setFont(titleLabel, 4);
			titleLabel.setBounds(550, 30, 240, 40);
			announcementPanel.add(titleLabel);
	        
            Vector<Vector<Object>> announcements=roatCtrl.InfoChange(0);
			
			Vector<String> columnsNames=new Vector<String>();
			columnsNames.add("选中");
			columnsNames.add("标题");
			columnsNames.add("创建时间");
			columnsNames.add("发布对象");
			columnsNames.add("发布状态");
			
			
			final MyTable2 table=new MyTable2(announcements,columnsNames,new int[]{100,500,300,150,150},"公告表",user);
			final JScrollPane scrollPane = new JScrollPane();
			scrollPane.setViewportView(table);
			scrollPane.getViewport().setBackground(new Color(252,251,248));
			scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); 
            scrollPane.setBounds(45, 80, 1200, 460);
            announcementPanel.add(scrollPane);
            
	        
	        JButton addButton = new JButton("添加");
	        CommonUtil.setFont(addButton, 7);
	        addButton.setBackground(new Color(142,240,146));
	        addButton.setForeground(new Color(64,60,69));
	        addButton.setBounds(500, 560, 100, 30);
	        announcementPanel.add(addButton);
	        addButton.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					createAnnounceInfoPanel(null, scrollPane);
				}
			});
	        
	        JButton delButton = new JButton("删除");
	        CommonUtil.setFont(delButton, 7);
	        delButton.setBackground(new Color(209,138,249));
	        delButton.setForeground(new Color(64,60,69));
	        delButton.setBounds(700, 560, 100, 30);
	        delButton.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					roatCtrl.delAnnouncements(scrollPane,user);
				}
			});
	        announcementPanel.add(delButton);
			tabbPane.setComponentAt(0, announcementPanel);
		}else if(tabbPane.getSelectedIndex()==1){
			userPanel = new JPanel();
			userPanel.setBackground(new Color(200,221,242));
			userPanel.setLayout(null);
			
			JRadioButton teacherRadio=new JRadioButton("教师用户");
			teacherRadio.setSelected(true);
			teacherRadio.setActionCommand("教师");
			CommonUtil.setFont(teacherRadio, 1);
			teacherRadio.setOpaque(false);
			teacherRadio.setBounds(470, 40,160, 30);
			userPanel.add(teacherRadio);
			
			JRadioButton studentRadio=new JRadioButton("学生用户");
			studentRadio.setActionCommand("学生");
			CommonUtil.setFont(studentRadio, 1);
			studentRadio.setOpaque(false);
			studentRadio.setBounds(670,40,160,30);
			userPanel.add(studentRadio);
			
            JPanel findPanel=CommonUtil.createFinPanel("教号|姓名");
            findPanel.setLocation(945, 40);
            userPanel.add(findPanel);
            final JTextField findField=(JTextField)findPanel.getComponent(0);
            JLabel findLabel=(JLabel)findPanel.getComponent(1);
            
			final ButtonGroup userGroup=new ButtonGroup();
			userGroup.add(teacherRadio);
			userGroup.add(studentRadio);
			
			final Vector<Vector<Object>> teachers=roatCtrl.InfoChange(1);
			final Vector<String> columnsNames=new Vector<String>();
			columnsNames.add("选中");
			columnsNames.add("教号");
			columnsNames.add("姓名");
			columnsNames.add("性别");
			columnsNames.add("年龄");
			columnsNames.add("学历");
			columnsNames.add("职衔");
			final MyTable2 table=new MyTable2(teachers,columnsNames,new int[]{100,150,150,100,100,200,300},"教师表",user);
			
			final JScrollPane scrollPane = new JScrollPane();
			scrollPane.setViewportView(table);
			scrollPane.getViewport().setBackground(new Color(252,251,248));
			scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); 
            scrollPane.setBounds(45,90,1200,480);
            scrollPane.setBorder(BorderFactory.createEtchedBorder());
            userPanel.add(scrollPane);
            
            teacherRadio.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				findField.setText(" 教号|姓名");
				findField.setForeground(Color.gray);
				final MyTable2 table=new MyTable2(teachers,columnsNames,new int[]{100,150,150,100,100,200,300},"教师表",user);
				scrollPane.setViewportView(table);
				}
			});
            studentRadio.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					findField.setText(" 学号|姓名|班级");
					findField.setForeground(Color.gray);
					final Vector<Vector<Object>> students=roatCtrl.InfoChange(10);
					final Vector<String> columnsNames=new Vector<String>();
					columnsNames.add("选中");
					columnsNames.add("学号");
					columnsNames.add("姓名");
					columnsNames.add("班级");
					columnsNames.add("性别");
					columnsNames.add("年龄");
					columnsNames.add("政治面貌");
				final MyTable2 table=new MyTable2(students,columnsNames,new int[]{100,200,200,100,100,250,250},"学生表",user);
				scrollPane.setViewportView(table);
				}
			});
            findLabel.addMouseListener(new MouseListener() {
				public void mouseReleased(MouseEvent e) {
					
				}
				public void mousePressed(MouseEvent e) {
				}
				
				@Override
				public void mouseExited(MouseEvent e) {
				}
				public void mouseEntered(MouseEvent e) {
				}
				public void mouseClicked(MouseEvent e) {
					if(findField.getForeground()!=Color.gray){
						String text=findField.getText().trim();
					    if(userGroup.getSelection().getActionCommand().equals("教师")){
					    	roatCtrl.findDataValues(scrollPane,text,"教师",user);
					    }else{
					    	roatCtrl.findDataValues(scrollPane,text,"学生",user);
					    }
					    
					}
						
				}
			});
            
	        JButton addButton = new JButton("添加");
	        CommonUtil.setFont(addButton, 7);
	        addButton.setBackground(new Color(142,240,146));
	        addButton.setForeground(new Color(64,60,69));
	        addButton.setBounds(480, 580, 120, 30);
	        userPanel.add(addButton);
	        addButton.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					if(userGroup.getSelection().getActionCommand().equals("教师")){
						createTeacherPanel(null, scrollPane);
					}
				}
			});
	        
	        JButton delButton = new JButton("删除");
	        CommonUtil.setFont(delButton, 7);
	        delButton.setBackground(new Color(209,138,249));
	        delButton.setForeground(new Color(64,60,69));
	        delButton.setBounds(710, 580, 120, 30);
	        delButton.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					roatCtrl.delAnnouncements(scrollPane,user);
				}
			});
	        userPanel.add(delButton);
			
			tabbPane.setComponentAt(1, userPanel);
		}else{
            JPanel selfInfoPanel = new JPanel();
			
			tabbPane.setComponentAt(2, selfInfoPanel);
			
		}
	
	}
	
	
	
	public static JPanel createAnnounceInfoPanel(final Announcement announcement,final JScrollPane scrollPane){
		final JPanel announceInfoPanel=new JPanel();
		announceInfoPanel.setLayout(null);
		
		JPanel centerPanel=new JPanel();
		centerPanel.setLayout(null);
		centerPanel.setBackground(new Color(200,221,242));
		centerPanel.setBounds(0, 0,980, 640);
		announceInfoPanel.add(centerPanel);
		
        JLabel titleLabel = new JLabel("公告信息");
		CommonUtil.setFont(titleLabel, 4);
		titleLabel.setBounds(400, 30, 240, 40);
		centerPanel.add(titleLabel);
        
		
		JLabel anounceTitleLabel=new JLabel("<html>标题<font color='red'>*</font></html>");
		CommonUtil.setFont(anounceTitleLabel,1);
		anounceTitleLabel.setBounds(80,110,60, 40);
		centerPanel.add(anounceTitleLabel);
		
		final JTextField titleField = new JTextField();
		if(announcement!=null){
			titleField.setText(announcement.getTitle());
		}
		CommonUtil.setFont(titleField,8);
		titleField.setBounds(140,110,760,40);
		titleField.addFocusListener(new FocusListener() {
			public void focusLost(FocusEvent e) {
				titleField.setBackground(new Color(255,255,255));
			}
			public void focusGained(FocusEvent e) {
				titleField.setBackground(new Color(254,254,215));
			}
		});
		centerPanel.add(titleField);
		
		JLabel contentLabel=new JLabel("<html>内容<font color='red'>*</font></html>");
		CommonUtil.setFont(contentLabel,1);
		contentLabel.setBounds(80,160,60, 40);
		centerPanel.add(contentLabel);
		
		final JTextPane contentPane=new JTextPane();
		if(announcement!=null){
			contentPane.setText(announcement.getContent());
		}
		CommonUtil.setFont(contentPane,5);
		contentPane.addFocusListener(new FocusListener() {
			public void focusLost(FocusEvent e) {
				contentPane.setBackground(new Color(255,255,255));
			}
			public void focusGained(FocusEvent e) {
				contentPane.setBackground(new Color(254,254,215));
			}
		});
		final JScrollPane scrollPane1 = new JScrollPane();
		scrollPane1.setViewportView(contentPane);
		scrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); 
        scrollPane1.setBounds(140,170,760,420);
		centerPanel.add(scrollPane1);
		
		JPanel rightPanel=new JPanel();
		rightPanel.setLayout(null);
		rightPanel.setBounds(980, 0, 305, 640);
		rightPanel.setBorder(new LineBorder(Color.lightGray, 1));
		//rightPanel.setBackground(new Color(244,204,252));
		announceInfoPanel.add(rightPanel);
		
		
		JLabel createTitleLabel=new JLabel("创建信息");
		CommonUtil.setFont(createTitleLabel,10);
		createTitleLabel.setBounds(70,50,160,40);
		rightPanel.add(createTitleLabel);
		
		
	    JLabel createPersonLabel=new JLabel("<html>创建人:</html>");
		CommonUtil.setFont(createPersonLabel,9);
		createPersonLabel.setBounds(15,110,75,30);
		rightPanel.add(createPersonLabel);
		
		final JTextField createPersonField = new JTextField();
		createPersonField.setForeground(new Color(135,98,243));
		createPersonField.setBackground(new Color(238,238,238));
		if(announcement!=null){
			createPersonField.setText(announcement.getUser_id());
		}else{
			if(user!=null){
				createPersonField.setText(user.getUserId());	
			}if(user==null){
				createPersonField.setText("3113007321");	
			}
			
		}
		CommonUtil.setFont(createPersonField,5);
		createPersonField.setEditable(false);
		createPersonField.setBounds(90,110,200,30);
		rightPanel.add(createPersonField);
		
		JLabel createTimeLabel=new JLabel("创建时间:");
		CommonUtil.setFont(createTimeLabel,9);
		createTimeLabel.setBounds(15,160,95,30);
		rightPanel.add(createTimeLabel);
		
		final JTextField createTimeField = new JTextField();
		createTimeField.setForeground(new Color(135,98,243));
		createTimeField.setBackground(new Color(238,238,238));
		if(announcement!=null){
			createTimeField.setText(announcement.getCreateTime().toString());
		}else{
			 new Thread() {
			        public void run() {
			            try {
			                while (true) {
			                	createTimeField.setText(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));//显示当前时间
			                    Thread.sleep(1000);//暂停一秒
			                }
			            } catch (Exception e) {
			            }
			        }
			    }.start();
		}
		CommonUtil.setFont(createTimeField,5);
		createTimeField.setEditable(false);
		createTimeField.setBounds(110,160,180,30);
		rightPanel.add(createTimeField);
	    
		JLabel viewLabel=new JLabel("<html>发布对象<font color='red'>*</font></html>");
		CommonUtil.setFont(viewLabel,9);
		viewLabel.setBounds(15,205,95,40);
		rightPanel.add(viewLabel);
		
		final JComboBox<String> viewBox=new JComboBox<String>();
		CommonUtil.setFont(viewBox,2);
		viewBox.setBackground(new Color(255,255,255));
		viewBox.setForeground(new Color(78,83,87));
	    viewBox.addItem("学生");
	    viewBox.addItem("教师");
	    viewBox.addItem("管理员");
	    viewBox.addItem("师生");
	    viewBox.addItem("全体");
	    viewBox.setBounds(110,210,180,30);
	    rightPanel.add(viewBox);
	  
	    JLabel releaseLabel=new JLabel("发布状态:");
		CommonUtil.setFont(releaseLabel,9);
		releaseLabel.setBounds(15,255,95,40);
		rightPanel.add(releaseLabel);
		
		JRadioButton radio0=new JRadioButton("未发布");
		CommonUtil.setFont(radio0, 7);
		radio0.setActionCommand("0");
		radio0.setEnabled(false);
		radio0.setOpaque(false);
		radio0.setBounds(120,260,100,25);
		rightPanel.add(radio0);
		
		JRadioButton radio1=new JRadioButton("已发布");
		CommonUtil.setFont(radio1, 7);
		radio1.setActionCommand("1");
		radio1.setEnabled(false);
		radio1.setOpaque(false);
		radio1.setBounds(120,290,100,25);
		rightPanel.add(radio1);
		
		JRadioButton radio2=new JRadioButton("已撤销");
		CommonUtil.setFont(radio2, 7);
		radio2.setActionCommand("2");
		radio2.setEnabled(false);
		radio2.setOpaque(false);
		radio2.setBounds(120,320,100,25);
		rightPanel.add(radio2);
		
		final ButtonGroup buttonGroup=new ButtonGroup();
		buttonGroup.add(radio0);
		buttonGroup.add(radio1);
		buttonGroup.add(radio2);
		if(announcement!=null){
			int releaseState=announcement.getReleas_state();
			if(releaseState==0){
				radio0.setSelected(true);
			}else if(releaseState==1){
				radio1.setSelected(true);
			}else{
				radio2.setSelected(true);
			}
		}else{
			radio0.setSelected(true);
		}
		
		JLabel remarkLabel=new JLabel("备注:");
		CommonUtil.setFont(remarkLabel,9);
		remarkLabel.setBounds(15,360,55,30);
		rightPanel.add(remarkLabel);
		
		final JTextPane remarkPane=new JTextPane();
		if(announcement!=null){
			remarkPane.setText(announcement.getRemark());
		}
		CommonUtil.setFont(remarkPane,5);
		remarkPane.setBounds(70,360,220,150);
		remarkPane.addFocusListener(new FocusListener() {
			public void focusLost(FocusEvent e) {
				remarkPane.setBackground(new Color(255,255,255));
			}
			public void focusGained(FocusEvent e) {
				remarkPane.setBackground(new Color(254,254,215));
			}
		});
		rightPanel.add(remarkPane);
		
		
		
        final JButton saveButton = new JButton("保存");
        CommonUtil.setFont(saveButton, 7);
        saveButton.setBackground(new Color(142,240,146));
        saveButton.setForeground(new Color(64,60,69));
        if(announcement==null){
        	saveButton.setActionCommand("add");
        }else{
        	saveButton.setActionCommand("update");
        }
        
        saveButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
        saveButton.setBounds(40, 530,100, 30);
        rightPanel.add(saveButton);
        saveButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String announceNo=null;
				if(announcement!=null){
					announceNo=announcement.getAnnounce_no();
				}else{
					announceNo="a"+CommonUtil.getRandom(3);
				}
				boolean save=roatCtrl.saveAnnouncement(announceInfoPanel,scrollPane,saveButton,announceNo,titleField,contentPane,createPersonField,createTimeField,viewBox,buttonGroup,remarkPane,user);
				if(save){
				announceInfoPanel.setVisible(false);
				announcementPanel.setVisible(true);
				tabbPane.setComponentAt(0, announcementPanel);
				}
			}
		});
        
        final JButton releaseButton = new JButton("发布");
        CommonUtil.setFont(releaseButton, 7);
        releaseButton.setEnabled(!radio1.isSelected());
        releaseButton.setBackground(new Color(242,247,156));
        releaseButton.setForeground(new Color(64,60,69));
        if(announcement==null){
        	releaseButton.setActionCommand("add");
        }else{
        	releaseButton.setActionCommand("update");
        }
        
        releaseButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
        releaseButton.setBounds(160, 530,100, 30);
        rightPanel.add(releaseButton);
        releaseButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String announceNo=null;
				if(announcement!=null){
					announceNo=announcement.getAnnounce_no();
				}else{
					announceNo="a"+CommonUtil.getRandom(3);
				}
				boolean release=roatCtrl.saveAnnouncement(announceInfoPanel,scrollPane,releaseButton,announceNo,titleField,contentPane,createPersonField,createTimeField,viewBox,buttonGroup,remarkPane,user);
				if(release){
				announceInfoPanel.setVisible(false);
				announcementPanel.setVisible(true);
				tabbPane.setComponentAt(0, announcementPanel);
				}
			}
		});
        
        final JButton revokeButton = new JButton("撤销");
        CommonUtil.setFont(revokeButton, 7);
        revokeButton.setEnabled(!radio2.isSelected());
        revokeButton.setBackground(new Color(144,195,246));
        revokeButton.setForeground(new Color(64,60,69));
        if(announcement==null){
        	revokeButton.setActionCommand("add");
        }else{
        	revokeButton.setActionCommand("update");
        }
        
        revokeButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
        revokeButton.setBounds(40, 570,100, 30);
        rightPanel.add(revokeButton);
        revokeButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String announceNo=null;
				if(announcement!=null){
					announceNo=announcement.getAnnounce_no();
				}else{
					announceNo="a"+CommonUtil.getRandom(3);
				}
				boolean revoke=roatCtrl.saveAnnouncement(announceInfoPanel,scrollPane,revokeButton,announceNo,titleField,contentPane,createPersonField,createTimeField,viewBox,buttonGroup,remarkPane,user);
				if(revoke){
				announceInfoPanel.setVisible(false);
				announcementPanel.setVisible(true);
				tabbPane.setComponentAt(0, announcementPanel);
				}
			}
		});
        
        
        
        JButton backButton = new JButton("返回");
        CommonUtil.setFont(backButton, 7);
        backButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
        backButton.setBackground(new Color(209,138,249));
        backButton.setForeground(new Color(64,60,69));
        backButton.setBounds(160, 570, 100, 30);
        backButton.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
				announceInfoPanel.setVisible(false);
				announcementPanel.setVisible(true);
				tabbPane.setComponentAt(0, announcementPanel);
			}
		});
        rightPanel.add(backButton);
        announcementPanel.setVisible(false);
		tabbPane.setComponentAt(0, announceInfoPanel);
		
		return announceInfoPanel;
	}
	
	
	
	
	private static JPanel createTeacherPanel(final Teacher teacher,final JScrollPane scrollPane){
		JPanel teacherPanel=new JPanel();
		teacherPanel.setLayout(null);
		teacherPanel.setBackground(new Color(200,221,242));
		
		JLabel titleLabel = new JLabel("教师用户",JLabel.CENTER);
		CommonUtil.setFont(titleLabel, 4);
		titleLabel.setBounds(550,30,220,40);	
		teacherPanel.add(titleLabel);	
		
		final JPanel infoPanel=new JPanel();
		infoPanel.setLayout(null);
		infoPanel.setBorder(BorderFactory.createLineBorder(new Color(110,110,110), 1));
		//infoPanel.setOpaque(false);
		infoPanel.setBounds(45, 90, 1200, 490);
		
		
        final JLabel picturelabel=CommonUtil.creatLabel(infoPanel, "", 940, 20, 240, 280);
        picturelabel.setBorder(BorderFactory.createLineBorder(Color.gray, 1));
        
        
		CommonUtil.creatLabel(infoPanel, "<html>教 &nbsp;&nbsp;&nbsp;&nbsp;号:<font color='red'>*</font></html>", 40, 20, 110, 35);
		final JTextField idField=CommonUtil.creaTextField(infoPanel, 150, 20,150, 35);
		idField.setOpaque(false);
		idField.setEditable(false);
		idField.setBorder(BorderFactory.createEmptyBorder());
		
		CommonUtil.creatLabel(infoPanel, "<html>姓 &nbsp;&nbsp;&nbsp;&nbsp;名:<font color='red'>*</font></html>", 350, 20, 110, 35);
		JTextField nameField=CommonUtil.creaTextField(infoPanel, 460, 20,150, 35);
		
		CommonUtil.creatLabel(infoPanel, "<html>性 &nbsp;&nbsp;&nbsp;&nbsp;别:<font color='red'>*</font></html>", 660, 20, 110, 35);
		JTextField sexField=CommonUtil.creaTextField(infoPanel, 770, 20,150, 35);
		
		
		CommonUtil.creatLabel(infoPanel, "<html>婚 &nbsp;&nbsp;&nbsp;&nbsp;姻:<font color='red'>*</font></html>", 40, 80, 110, 35);
		JTextField marriageField=CommonUtil.creaTextField(infoPanel, 150, 80,150, 35);
		
		CommonUtil.creatLabel(infoPanel, "<html>学 &nbsp;&nbsp;&nbsp;&nbsp;历:<font color='red'>*</font></html>", 350, 80, 110, 35);
		JTextField educateField=CommonUtil.creaTextField(infoPanel, 460, 80,150, 35);
		
		CommonUtil.creatLabel(infoPanel, "<html>职 &nbsp;&nbsp;&nbsp;&nbsp;衔:<font color='red'>*</font></html>", 660, 80, 110, 35);
		JTextField jobField=CommonUtil.creaTextField(infoPanel, 770, 80,150, 35);
		
		
		CommonUtil.creatLabel(infoPanel, "<html>出生日期:<font color='red'>*</font></html>", 40, 140, 120, 35);
		DateChooser dateChooser=null;
		if(teacher==null){
			dateChooser=new DateChooser();
        }else{
        	SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日");
    		Date birthStr = null;
			try {
				birthStr = sdf.parse(teacher.getBirth());
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	dateChooser=new DateChooser(birthStr);
        }
        dateChooser.setBorder(BorderFactory.createEmptyBorder());
        dateChooser.setBounds(160, 140, 290, 35);
        infoPanel.add(dateChooser);
        
		CommonUtil.creatLabel(infoPanel, "<html>电话号码:<font color='red'>*</font></html>", 510, 140, 120, 35);
		JTextField phoneField=CommonUtil.creaTextField(infoPanel, 630, 140,290, 35);
		
		
		CommonUtil.creatLabel(infoPanel, "<html>政治面貌:<font color='red'>*</font></html>", 40, 200, 120, 35);
		JTextField politicalField=CommonUtil.creaTextField(infoPanel, 160, 200,290, 35);
		
		CommonUtil.creatLabel(infoPanel, "<html>身份证号:<font color='red'>*</font></html>", 510, 200, 120, 35);
		JTextField identifyField=CommonUtil.creaTextField(infoPanel, 630, 200,290, 35);
		
		
		CommonUtil.creatLabel(infoPanel, "毕业高校:", 40, 260, 110, 35);
		JTextField graduateField=CommonUtil.creaTextField(infoPanel, 150, 260,770, 35);
		
		CommonUtil.creatLabel(infoPanel, "家庭住址:", 40, 320, 110, 35);
		JTextField addressField=CommonUtil.creaTextField(infoPanel, 150, 320,770, 35);
		
		JLabel upLoadLabel=CommonUtil.creatLabel(infoPanel, "<html><u><font color='blue'>上传图片</font></u><html>", 1000, 310, 110, 35);
		upLoadLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
		upLoadLabel.setOpaque(true);
		upLoadLabel.setBorder(BorderFactory.createRaisedBevelBorder());
		upLoadLabel.setBackground(new Color(236,216,247));
		upLoadLabel.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseEntered(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseClicked(MouseEvent e) {
				FileTest jf=new FileTest(infoPanel);
				File file=jf.getSelectedFile();
				String path=file.getPath();
				byte[] picture=CommonUtil.getPictureByte(file);
				File photoFile=CommonUtil.writePictureFile(idField.getText(), picture);
				ImageIcon photo=new ImageIcon("src/com/util/images/"+idField.getText()+".jpg");
				photo.setImage(photo.getImage().getScaledInstance(240,280,Image.SCALE_DEFAULT));
				picturelabel.setIcon(photo);
			}
		});
		
		if(teacher!=null){
			idField.setText(teacher.getTeaNo());
			nameField.setText(teacher.getName());
			sexField.setText(teacher.getSex());
			marriageField.setText(teacher.getMarriage());
			educateField.setText(teacher.getEducate());
			jobField.setText(teacher.getJobGrade());
			phoneField.setText(teacher.getPhone());
			politicalField.setText(teacher.getPoliticalStatusString());
			graduateField.setText(teacher.getGraduate());
			addressField.setText(teacher.getAddress());
			identifyField.setText(teacher.getIdentity());
		}else{
			idField.setText(CommonUtil.getRandom(10));
			
			JButton backButton=CommonUtil.createButton(infoPanel,new Color(242,247,156), "继续添加", 800, 440, 120, 30);

		}
		JCheckBox roatSetBox=new JCheckBox("是否设置管理员");
		CommonUtil.setFont(roatSetBox,1);
		roatSetBox.setBorder(BorderFactory.createEmptyBorder());
		roatSetBox.setOpaque(false);
		roatSetBox.setBounds(40, 380,200, 30);
		infoPanel.add(roatSetBox);
		
		
		JButton saveButton=CommonUtil.createButton(infoPanel, new Color(142,240,146), "保存", 400, 440, 120, 30);
		JButton backButton=CommonUtil.createButton(infoPanel,new Color(209,138,249), "返回", 600, 440, 120, 30);

		teacherPanel.add(infoPanel);
		
		
		userPanel.setVisible(false);
		teacherPanel.setVisible(true);
		tabbPane.setComponentAt(1, teacherPanel);
		return teacherPanel;
		
	}
	
}
